package com.wei.duowan.bbs.ui.adapter;

import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.wei.duowan.bbs.ui.fragment.BaseFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者：赵若位
 * 时间：2019/8/2 16:25
 * 联系方式：1070138445
 * 功能：
 */
public class BaseViewPagerAdapter extends FragmentStatePagerAdapter
{
    private List<BaseFragment> mFragments;


    public BaseViewPagerAdapter(FragmentManager fm)
    {
        super(fm);
        mFragments = new ArrayList<>();
    }


    public void setNewData(@Nullable List<BaseFragment> list)
    {
        this.mFragments.clear();
        this.mFragments.addAll(list == null ? new ArrayList<BaseFragment>() : list);
        notifyDataSetChanged();
    }

    @Override
    public Fragment getItem(int position)
    {
        return mFragments.get(position);
    }

    @Override
    public int getCount()
    {
        return mFragments.size();
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position)
    {
        BaseFragment fragment = mFragments.get(position);
        return fragment.getArguments().getString(BaseFragment.TAG);
    }
}
